package com.juhuacha.tryrxjava;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.jakewharton.rxbinding.view.RxView;
import com.juhuacha.tryrxjava.ExoPlayer;
import com.juhuacha.tryrxjava.IjkAct;
import com.juhuacha.tryrxjava.R;
import com.juhuacha.tryrxjava.SearchAct;

import rx.Observable;
import rx.Scheduler;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

public class MainActivity extends AppCompatActivity {

    public  String CARL = "http://d.hiphotos.baidu.com";
    public  String CARLS = "/zhidao/pic/item/6159252dd42a283487f49d5559b5c9ea15cebf1a.jpg";
    public  String PHEONIX = "http://img5.imgtn.bdimg.com";
    public  String PHEONIXS = "/it/u=2478060237,2271619272&fm=21&gp=0.jpg";

    private ImageView img;
    private Button ijk;
    private Button exo;
    private Button search;
    private Button type;
    private Button bar;
    private Button customscrollview;
    private Button translation;
    private Button demo;
    private Button recycler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });

        img = (ImageView) findViewById(R.id.img);
        Observable.just(CARL)
                .map(new Func1<String, String>() {
                    @Override
                    public String call(String s) {
                        return s + CARLS;
                    }
                })
                .subscribeOn(AndroidSchedulers.mainThread())
                .observeOn(Schedulers.immediate())
                .subscribe(new Action1<String>() {
                    @Override
                    public void call(String s) {
                        Glide.with(MainActivity.this).load(s).placeholder(R.mipmap.ic_launcher).into(img);
                    }
                });
        ijk = (Button) findViewById(R.id.ijk);
        exo = (Button) findViewById(R.id.exo);
        search = (Button) findViewById(R.id.search);
        type = (Button) findViewById(R.id.typetext);
        bar = (Button) findViewById(R.id.custombar);
        customscrollview = (Button) findViewById(R.id.customscrollview);
        translation = (Button) findViewById(R.id.translation);
        demo = (Button) findViewById(R.id.demo);
        recycler = (Button) findViewById(R.id.recycler);

        RxView.clicks(ijk).subscribe(new Action1<Void>() {
            @Override
            public void call(Void aVoid) {
                startActivity(new Intent(MainActivity.this,IjkAct.class));
            }
        });
        RxView.clicks(exo).subscribe(new Action1<Void>() {
            @Override
            public void call(Void aVoid) {
                startActivity(new Intent(MainActivity.this,ExoPlayer.class));
            }
        });
        RxView.clicks(search)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        startActivity(new Intent(MainActivity.this,SearchAct.class));
                    }
                });
        RxView.clicks(type)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        startActivity(new Intent(MainActivity.this,TypeTextAct.class));
                    }
                });
        RxView.clicks(bar)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        startActivity(new Intent(MainActivity.this,CustomBarAct.class));
                    }
                });
        RxView.clicks(customscrollview)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        startActivity(new Intent(MainActivity.this,CustomScrollView.class));
                    }
                });
        RxView.clicks(translation)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        startActivity(new Intent(MainActivity.this,CustomScrollView.class));
                    }
                });
        RxView.clicks(demo)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        startActivity(new Intent(MainActivity.this,DemoAct.class));
                    }
                });
        RxView.clicks(recycler)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        startActivity(new Intent(MainActivity.this,RecyclerViewDemoAct.class));
                    }
                });
    }

    /**
     * ijk
     * @param v
     */
    public void goIjk(View v){

    }

    /**
     * exo
     * @param v
     */
    public void goExo(View v){

    }
}
